/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.boxin.ims.modules.wechat.service.screen;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.BaseService;
import com.boxin.ims.modules.wechat.entity.screen.ScreenConfig;
import com.boxin.ims.modules.wechat.dao.screen.ScreenConfigDao;

/**
 * 微信墙Service
 * @author Jakemanse
 * @version 2013-11-01
 */
@Component
@Transactional(readOnly = true)
public class ScreenConfigService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(ScreenConfigService.class);
	
	@Autowired
	private ScreenConfigDao screenConfigDao;
	
	public ScreenConfig get(Long id) {
		return screenConfigDao.findOne(id);
	}
	
	public Page<ScreenConfig> find(Page<ScreenConfig> page, ScreenConfig screenConfig) {
		DetachedCriteria dc = screenConfigDao.createDetachedCriteria();
		if (screenConfig.getUser()!=null && screenConfig.getUser().getId()>0){
			dc.add(Restrictions.eq("user.id", screenConfig.getUser().getId()));
		}
		if (StringUtils.isNotEmpty(screenConfig.getRemarks())){
			dc.add(Restrictions.like("remarks", "%"+screenConfig.getRemarks()+"%"));
		}
		dc.addOrder(Order.desc("id"));
		return screenConfigDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(ScreenConfig screenConfig) {
		screenConfigDao.save(screenConfig);
	}
	
	@Transactional(readOnly = false)
	public void delete(Long id) {
		screenConfigDao.deleteById(id);
	}
	
}
